package ship.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ship.entity.usertable;
import ship.service.shipservice;

/**
 * Servlet implementation class updatemyusertable
 */
@WebServlet("/updatemyusertable")
public class updatemyusertable extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public updatemyusertable() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	       //获取待修改的人的sid
		   request.setCharacterEncoding("utf-8");
	       int id = Integer.parseInt(request.getParameter("sid"));
	       //获取 修改后的内容
	       String name = request.getParameter("sname");
	       String email = request.getParameter("semail");
	       String age = request.getParameter("sage");
	       String hobby = request.getParameter("shobby");
	       String ct = request.getParameter("sct");
	       String address = request.getParameter("saddress");
	       //封装实体类
	       usertable user = new usertable(id,name,email,age,hobby,ct,address);
	       
	       shipservice service = new shipservice();
	       boolean result = service.updateusertable(id, user);
	       response.setContentType("text/html; charset=utf-8");
		   response.setCharacterEncoding("utf-8");
		    if(result) {
	            String mess = "修改信息成功!";
	            request.setAttribute("mess", mess); 
	            request.getRequestDispatcher("querymyuserServlet").forward(request, response);
		    }else {
	            String mess = "请勿重复操作!";
	            request.setAttribute("mess", mess); 
	            request.getRequestDispatcher("querymyuserServlet").forward(request, response);	
		    }
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
